package com.wf.course.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.utils.page.PageBean;
import com.wf.course.dao.IRoleMapper;
import com.wf.course.model.user.Role;
import com.wf.course.service.IRoleService;
@Service
@Transactional(rollbackFor=Exception.class)
public class IRoleServiceImpl implements IRoleService{

	@Autowired
	private IRoleMapper roleMapper;
	
	/**
	 * 首页列表
	 * @param pageBean
	 */
	@Override
	public void indexInfo(PageBean<Role> pageBean) {
		pageBean.setResults(this.roleMapper.queryList(pageBean));
		pageBean.setTotalCount(this.roleMapper.getTotalCount(pageBean).intValue());
	}

	/**
	 * 添加或更新用户信息
	 */
	@Override
	@Transactional(rollbackFor={Exception.class,RuntimeException.class})
	public void saveOrUpdateRole(Role role) {
		String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
		if(role.getId()==null){
			role.setCreateTime(time);
			this.roleMapper.saveRole(role);
		}else{
			this.roleMapper.updateRole(role);
		}
	}
	/**
	 * 查询用户信息
	 */
	@Override
	public Role querRoleByRoleId(Integer id) {
		return this.roleMapper.queryRoleByRoleId(id);
	}

	@Override
	public void deleteById(Integer id) {
		this.roleMapper.deleteById(id);
	}
	@Override
	public List<Role> queryRoles(){
		return this.roleMapper.queryRoles();
	}
	
}
